package com.turing.data.scripts.contract.filter


import com.turing.common.util.FileUtils
import com.turing.common.util.StringUtils
import com.turing.data.engine.CombineLongText
import com.turing.data.engine.utils.ScriptsUtils
import com.turing.data.vo.out.review.DependParamsVO
import com.turing.data.vo.out.review.TaskElementVO

class IfRequirement_30178_10_filter {

    static List< TaskElementVO.DrawResultVO > doConvert(DependParamsVO dependParams){

        String REGEX_BEFORE = "初始销售期间认购款项及利息的处理方式投资者的认购参与款项（不含认购费用）"
        String REGEX_AFTER = "加计其在初始销售期形成的利息将折算为资产管理计划份额归投资者所有"

        def textPathMap = dependParams.textPathMap

        List<TaskElementVO.DrawResultVO > trueValueSet = new ArrayList<>()
        List<TaskElementVO.DrawResultVO > resultVOs = ScriptsUtils.tryInitResult(dependParams)
        if (resultVOs!=null && resultVOs.size()>0) {
            for (int i = 0; i < resultVOs.size(); i++) {
                if(StringUtils.isEmpty(resultVOs.get(i).childTaskSn)){
//                    return  resultVOs
                    continue
                }
                def rawPath = textPathMap.get(resultVOs.get(i).childTaskSn)
                def rawText = FileUtils.loadJson(rawPath)
                String trueValue = CombineLongText.fetchNearbyText(resultVOs.get(i), rawText,40)

                if ( trueValue =~ REGEX_BEFORE || trueValue =~ REGEX_AFTER ){
                    trueValueSet.add(resultVOs.get(i))
                    return trueValueSet
                }
            }
        }

        TaskElementVO.DrawResultVO defaultDrawResultVO = new TaskElementVO.DrawResultVO()
        defaultDrawResultVO.text = "否"
        trueValueSet.add(defaultDrawResultVO)
        return  trueValueSet

    }

}
